/**
 * Created by ZFL on 2017/9/15.
 */

var vm = new Vue({
    el:'#goodsCom',
    data:{
        commentCount:0,             //全部评论数
        commentList:[]         //全部评价数据
    }
});
var goodsId = '';       //商品ID
function PageInit(){
    vm.commentCount = $.getPara('commentCount');
    goodsId = $.getPara('goodsId');
    getCommentData();
    infiniteSroll();
}

var pageNum = 1;
var pageSize = 10;
var loading = false;
function getCommentData(){
    $.ajaxHandler({
        model: function () {
            var obj = {};
            obj.goodId = goodsId;
            obj.pageNum = pageNum;
            obj.pageSize = pageSize;
            console.log(obj)
            return obj;
        },
        visibleTime: 0,
        dataType: "json",
        visible:'hide',
        api: 'yg_baijiaapporder/goodsComment/listGoodsCommentByGoodId',
        success: function (result) {
            //console.log(result);
            if(result.code == 10000){
                var data = result.data;
                if(data.list.length > 0){
                    // 加载数据
                    loading = false;
                    data.list.forEach(function(value,index){
                        value.imgArr = [];
                        if(value.image1 != ''){
                            value.imgArr.push(value.image1);
                        }
                        if(value.image2 != ''){
                            value.imgArr.push(value.image2);
                        }
                        if(value.image2 != ''){
                            value.imgArr.push(value.image3);
                        }
                        vm.commentList.push(value);
                    });
                    //console.log(vm.commentList);
                    //表示这是最后一页数据
                    if(data.pageCount == pageNum){
                        loading = true;
                    }
                }else {
                    loading = true;
                }
            }else{
                YDUI.dialog.toast(result.message, 'error', 1000);
            }
        }
    })
}

//滚动加载
function infiniteSroll() {
    $("body").infinite().on("infinite", function () {
        if (loading) return;
        loading = true;
        pageNum++;
        $('.weui-infinite-scroll-box').show();
        setTimeout(function () {
            loading = false;
            $('.weui-infinite-scroll-box').hide();
            storeInfo();
        }, 1500);   //模拟延迟
    });
}


//返回页面
function returnPage(){
    window.history.go(-1);
}